home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / ASM-ARM / ATOMIC.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  2KB  |  95 lines

  1. /*
  2.  * linux/include/asm-arm/atomic.h
  3.  *
  4.  * Copyright (c) 1996 Russell King.
  5.  *
  6.  * Changelog:
  7.  *  27-06-1996    RMK    Created
  8.  *  13-04-1997    RMK    Made functions atomic!
  9.  *  07-12-1997    RMK    Upgraded for v2.1.
  10.  *  26-08-1998    PJB    Added #ifdef __KERNEL__
  11.  */
  12. #ifndef __ASM_ARM_ATOMIC_H
  13. #define __ASM_ARM_ATOMIC_H
  14.  
  15. #ifdef __SMP__
  16. #error SMP not supported
  17. #endif
  18.  
  19. #include <linux/config.h>
  20.  
  21. #ifdef CONFIG_ARCH_CO285
  22. typedef struct { volatile int counter; } atomic_t;
  23. #else
  24. typedef struct { int counter; } atomic_t;
  25. #endif
  26.  
  27. #define ATOMIC_INIT(i)    { (i) }
  28.  
  29. #ifdef __KERNEL__
  30. #include <asm/system.h>
  31.  
  32. #define atomic_read(v)    ((v)->counter)
  33. #define atomic_set(v,i)    (((v)->counter) = (i))
  34.  
  35. static __inline__ void atomic_add(int i, volatile atomic_t *v)
  36. {
  37.     unsigned long flags;
  38.  
  39.     save_flags_cli (flags);
  40.     v->counter += i;
  41.     restore_flags (flags);
  42. }
  43.  
  44. static __inline__ void atomic_sub(int i, volatile atomic_t *v)
  45. {
  46.     unsigned long flags;
  47.  
  48.     save_flags_cli (flags);
  49.     v->counter -= i;
  50.     restore_flags (flags);
  51. }
  52.  
  53. static __inline__ void atomic_inc(volatile atomic_t *v)
  54. {
  55.     unsigned long flags;
  56.  
  57.     save_flags_cli (flags);
  58.     v->counter += 1;
  59.     restore_flags (flags);
  60. }
  61.  
  62. static __inline__ void atomic_dec(volatile atomic_t *v)
  63. {
  64.     unsigned long flags;
  65.  
  66.     save_flags_cli (flags);
  67.     v->counter -= 1;
  68.     restore_flags (flags);
  69. }
  70.  
  71. static __inline__ int atomic_dec_and_test(volatile atomic_t *v)
  72. {
  73.     unsigned long flags;
  74.     int result;
  75.  
  76.     save_flags_cli (flags);
  77.     v->counter -= 1;
  78.     result = (v->counter == 0);
  79.     restore_flags (flags);
  80.  
  81.     return result;
  82. }
  83.  
  84. static __inline__ void atomic_clear_mask(unsigned long mask, unsigned long *addr)
  85. {
  86.     unsigned long flags;
  87.  
  88.     save_flags_cli (flags);
  89.     *addr &= ~mask;
  90.     restore_flags (flags);
  91. }
  92.  
  93. #endif
  94. #endif
  95.